<template>
	<view class="w-tit-back" :style="{background: background }">
		<view :class="{ 'w-tit-back--fixed': fixed, 'w-tit-back--shadow': border, 'w-tit-back--border': border }" :style="{ 'background': background}" class="w-tit-back__content">
			<uni-status-bar v-if="statusBar" />
			<view :style="{ color: color}" class="w-tit-back__header w-tit-back__content_view">
				<view @tap="onClickLeft" class="w-tit-back__header-btns w-tit-back__header-btns-left w-tit-back__content_view">
					<view class="w-tit-back__content_view" v-if="leftIcon.length">
						<uni-icons :color="color" :type="leftIcon" :size="iconfont" />
					</view>
					<view :class="{ 'w-tit-back-btn-icon-left': !leftIcon.length }" class="w-tit-back-btn-text w-tit-back__content_view" v-if="leftText.length">
						<text :style="{ color: color, 'font-size': '14px' }">{{ leftText }}</text>
					</view>
					<slot name="left" />
				</view>
				<view class="w-tit-back__header-container w-tit-back__content_view">
					<view class="w-tit-back__header-container-inner w-tit-back__content_view" v-if="title.length">
						<text class="uni-nav-bar-text" :style="{'color': titcolor , 'font-size':fontSize +'px','font-weight':fontweight }">{{ title }}</text>
					</view>
					<!-- 标题插槽 -->
					<slot />
				</view>
				<view :class="title.length ? 'w-tit-back__header-btns-right' : ''" @tap="onClickRight" class="w-tit-back__header-btns w-tit-back__content_view">
					<view class="w-tit-back__content_view" v-if="rightIcon.length  && userType !== 'index'">
						<uni-icons :color="color" :type="rightIcon" :size="iconfont" fontWeight="600"/>
					</view>
					<!-- 优先显示图标 -->
					<view class="w-tit-back-btn-text w-tit-back__content_view" v-if="rightText.length && !rightIcon.length">
						<text class="uni-nav-bar-right-text" :style="{color:rightColor,'font-size':rightSize + 'px'}">{{ rightText }}</text>
					</view>
					<slot name="right" />
				</view>
			</view>
		</view>
		<view class="w-tit-back__placeholder" v-if="fixed">
			<uni-status-bar v-if="statusBar" />
			<view class="w-tit-back__placeholder-view" />
		</view>
	</view>
</template>

<script>
	import uniStatusBar from "@/components/uni-status-bar/uni-status-bar.vue";
	import uniIcons from "@/components/uni-icons/uni-icons.vue";

	export default {
		name: "w-tit-back",
		components: {
			uniStatusBar,
			uniIcons
		},
		props: {
			userType:{
				type:String,
				default:'user'
			},			
			title: {
				type: String,
				default: "标题"
			},
			leftText: {
				type: String,
				default: ""
			},
			rightText: {
				type: String,
				default: ""
			},
			leftIcon: {
				type: String,
				default: ""
			},
			iconfont: {
				type: String,
				default: "28"
			},
			rightIcon: {
				type: String,
				default: ""
			},
			rightColor:{
				type: String,
				default: ""
			},
			rightSize:{
				type: String,
				default: ""
			},
			fixed: {
				type: [Boolean, String],
				default: false
			},
			color: {
				type: String,
				default: "#fff"
			},
			titcolor:{
				type: String,
				default: "#333333"
			},
			fontweight:{
				type: String,
				default: "300"
			},
			fontSize:{
				type: String,
				default: "16"
			},
			background: {
				type: String,
				default: "rgba(255,255,255,0)"
			},
			statusBar: {
				type: [Boolean, String],
				default: false
			},
			shadow: {
				type: [String, Boolean],
				default: true
			},
			border: {
				type: [String, Boolean],
				default: true
			},
			is_back: {
				type: [String, Boolean],
				default: true
			}
		},
		mounted() {
			if (uni.report && this.title !== '') {
				uni.report('title', this.title)
			}
		},
		methods: {
			onClickLeft() {
				if(this.is_back){
					uni.navigateBack({
						delta: 1
					})
				}else{
					this.$emit("clickLeft");
				}
				
			},
			onClickRight() {
				this.$emit("clickRight");
			}
		}
	};
</script>

<style scoped>
	.uni-nav-bar-text {
		/* #ifdef APP-PLUS */
		font-size: 34rpx;
		/* #endif */
		/* #ifndef APP-PLUS */
		font-size: 32rpx;
		/* #endif */
	}

	.uni-nav-bar-right-text {
		font-size: 28rpx;
	}

	.w-tit-back {
		width: 750rpx;
		height: 90rpx;
		padding: 15rpx 6rpx;
	}

	.w-tit-back__content {
		position: relative;
		width: 750rpx;
		background-color: rgba(255,255,255,0);
		overflow: hidden;
	}

	.w-tit-back__content_view {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		align-items: center;
		flex-direction: row;
		/* background-color: #FFFFFF;
 */
	}

	.w-tit-back__header {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		width: 750rpx;
		height: 60rpx;
		line-height: 60rpx;
		font-size: 32rpx;
	}

	.w-tit-back__header-btns {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-wrap: nowrap;
		width: 110rpx;
		justify-content: center;
		align-items: center;
	}

	.w-tit-back__header-btns-left {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		width: 110rpx;
		justify-content: flex-start;
	}

	.w-tit-back__header-btns-right {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		width: 110rpx;
		padding-right: 20rpx;
		justify-content: flex-end;
	}

	.w-tit-back__header-container {
		flex: 1;
	}

	.w-tit-back__header-container-inner {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex: 1;
		align-items: center;
		justify-content: center;
		font-size: 28rpx;
	}


	.w-tit-back__placeholder-view {
		height: 30px;
	}

	.w-tit-back--fixed {
		position: fixed;
		z-index: 998;
	}

	.w-tit-back--shadow {
		
	}

	.w-tit-back--border {

	}
</style>